Creating Globalized ColdFusion Applications
Table of Contents
- Introduction
- Globalization Changes in ColdFusion MX
- Good Practices: Obstacles in Developing I18N Applications
- Good Practices (cont): Encoding, Unicode, HTML
- Good Practices (cont): Locale Determination, Locale-Specific Formatting, Time Zones
- Good Practices (cont): ResourceBundles,Application Framework, User Specific, Server Specific
Encoding
To quote the documentation in Developing ColdFusion MX Applications:
"A character encoding maps each character in a character set to a numeric value that can be represented by a computer. These numbers can be represented by a single byte or multiple bytes". You should note that charset and character encoding mean the same thing as far as ColdFusion MX is concerned. It’s not unusual for a language to have more than one encoding (for example English has both 8-bit ISO-8859-1 or Latin-1 and 7-bit ASCII and Japanese which has Shift-JIS, EUC-JP, and ISO-2022-JP encodings). To make matters interesting, not all characters for a given language are represented in every encoding used for that language. The Euro symbol for instance, isn’t found within the ISO-8859-1 encoding, simply because the ISO encoding came before the Euro was established as the default currency in the EU. Internally, ColdFusion uses Unicode (UCS-2), which is efficient to process because its fixed width (2 bytes per character). Bandwidth efficiency, however, requires single byte encoding.
One of the things I hate as a developer is that kind of variety. Getting the correct encoding matched to a language isn’t easy when there are multiple encodings for a language. In fact, getting it wrong happens so often that a Japanese term, "mojibake" or garbage, has crept into the I18N vernacular to explicitly describe this situation.
Simplifying development and long-term code management is more important than perceived bandwidth efficiency. I therefore strongly urge you to use a single encoding (UTF-8) for all your languages. Before you throw your hands in the air and shout, "That’s inefficient!" consider the nature of UTF-8. UTF-8 is a multibyte encoding, where a character can be represented by one to three or perhaps four bytes. While that might sound uneconomical, bear in mind:
- The vast majority of text transmitted on the Internet can be represented by ASCII, which UTF-8 encodes as one byte (7-bit).
- UTF-8 encodes non-ASCII characters such as those used in Western Europe, and Arabic countries as two bytes.
- Most Asian characters are encoded as three bytes.
UTF-8 encoding is as efficient as it needs to be. Do yourself a favor and introduce some simplicity to this process and use UTF-8. Don’t take my word for it, the latest W3C working draft on authoring I18N XHTML and HTML documents actually recommends using UTF-8 or other Unicode encoding: "Choose UTF-8 or another Unicode encoding for all content."
Unicode
My experience in the ColdFusion User Forums and various ColdFusion related mailing lists suggests that the arguments for using Unicode are again worth repeating:
- It’s a standard (as they say here in Thailand, "unicode same same ISO 10646").
- It’s Internet ready (XML, Perl, Java, Javascript, etc. all support Unicode).
- It’s multilingual.
- It travels well (text in any language can be easily exchanged globally).
- It offers monolithic text processing (and that of course saves you money in development and support costs, time to market, and so forth.).
- It has wide industry support (Macromedia, IBM, Microsoft, HP, Sun, Oracle, and so forth.) make it vendor neutral.
- It continuously evolves (it's now version 4.0).
- It's possible to convert from legacy code pages.
- It’s more or less apolitical.
- It's recommended by W3C for I18N html content.
- And let's not forget it's the default internal encoding for ColdFusion MX
Your application should use Unicode.
HTML
While ColdFusion overrides HTML-based character encoding META tags (specifically CONTENT-TYPE), it’s usually a good idea to include these, properly identified, in your ColdFusion pages. The main reasons for this are search engines and speech synthesizers. Remember our guiding principle of universal access? The three most important HTML tags from this perspective are:
- The HTML tag has two important I18N attributes:
- The
langattribute: This attribute specifies the base language of an element's attribute values and text content (note, you can apply the lang attribute to many HTML elements). Acceptable values for the lang attribute follow ISO639 and ISO3166, using a format such as “primary-language-code-subcode”, normally a two-letter country code but might also include language versions (for instance, the value may be "en-cockney", the Cockney version of English). - The
dirattribute: This attribute specifies the base direction of directionally neutral text. Text that doesn't have inherent directionality as defined in Unicode, like lang, dir can be applied to many HTML elements such as tables, inputs, and so forth. Acceptable values for the dir attribute are LTR (left-to-right) and RTL (right-to-left).
- The
- The CONTENT-LANGUAGE meta tag specifies the primary
human language(s) for a page. For example, the following META tag
indicates that the page has English as used in the United States,
Thai as used in Thailand, and French on this page.
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="en-US,th-TH,fr">
- The CONTENT-TYPE meta tag specifies the content
type, such as text/html and the character set used on this page.
This is one tag that I include out of habit. The META tag shown below
indicates that this page is plain text/html and uses UTF-8 character
set:
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
It is recommended that your ColdFusion pages include these three HTML tags with appropriate attribute values.